//
//  BFShOrderTableViewCell.m
//  BeautyFood
//
//  Created by apple on 2020/5/5.
//  Copyright © 2020 stoneobs. All rights reserved.
//

#import "BFShOrderTableViewCell.h"

@interface BFShOrderTableViewCell()
@property(nonatomic, strong) UIScrollView                     *scroll_view;/**<  */
@property(nonatomic, strong) UIView                     *normalContenView;/**<  */
@property(nonatomic, strong) NSMutableArray                     *imageView_array;/**<  */


@property(nonatomic, strong) UIImageView                     *iconImageView;/**<  */
@property(nonatomic, strong) STLabel                     *nameLable;/**<  */
@property(nonatomic, strong) STLabel                     *desLable;/**<  */
@end
@implementation BFShOrderTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self stoneobs_ui_configSubView];
    }
    return self;
}
+ (CGFloat)stoneobs_ui_cell_height{
    return 100;
}
#pragma mark --configSubView
- (void)stoneobs_ui_configSubView{
    self.backgroundColor = UIColor.clearColor;
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    self.scroll_view = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, STONEOBS_UI_UISCREEN_WIDTH - 0, self.class.stoneobs_ui_cell_height)];
    self.scroll_view.backgroundColor = UIColor.whiteColor;
    self.scroll_view.clipsToBounds = YES;
//    self.scroll_view.layer.cornerRadius = 8;
    self.scroll_view.showsHorizontalScrollIndicator = NO;
    [self.contentView addSubview:self.scroll_view];
    

    self.normalContenView = [[UIView alloc] initWithFrame:self.scroll_view.frame];
    [self.contentView addSubview:self.normalContenView];
    self.normalContenView.backgroundColor = UIColor.whiteColor;
    self.normalContenView.userInteractionEnabled = YES;
    
    UIImageView * stoneobs_ui_imageView = [[UIImageView alloc] initWithFrame:CGRectMake(12, 0, self.class.stoneobs_ui_cell_height, self.class.stoneobs_ui_cell_height)];
    stoneobs_ui_imageView.contentMode = UIViewContentModeScaleAspectFill;
    stoneobs_ui_imageView.clipsToBounds = YES;
    [self.normalContenView addSubview:stoneobs_ui_imageView];
    self.iconImageView = stoneobs_ui_imageView;
    CGFloat witdh = self.normalContenView.width - self.iconImageView.right - 20;
    ({
        STLabel * stoneobs_ui_label = [[STLabel alloc] initWithFrame:CGRectMake(stoneobs_ui_imageView.right+10, 0, witdh, 35)
                                                                text:@"dka;lsd"
                                                           textColor:STONEOBS_UI_FIRST_TEXT_COLOR
                                                                font:15
                                                         isSizetoFit:NO
                                                       textAlignment:NSTextAlignmentLeft];
        [self.normalContenView addSubview:stoneobs_ui_label];
        self.nameLable = stoneobs_ui_label;
    });
    
    ({
        STLabel * stoneobs_ui_label = [[STLabel alloc] initWithFrame:CGRectMake(stoneobs_ui_imageView.right+10, 0, witdh, 35)
                                                                text:@"dka;lsd"
                                                           textColor:STONEOBS_UI_THIRD_TEXT_COLOR
                                                                font:12
                                                         isSizetoFit:NO
                                                       textAlignment:NSTextAlignmentLeft];
        [self.normalContenView addSubview:stoneobs_ui_label];
        self.desLable = stoneobs_ui_label;
        stoneobs_ui_label.centerY = self.iconImageView.centerY;
    });
    
}
- (void)setModel:(BFShOrderModel *)model{
    _model = model;
    [self.imageView_array makeObjectsPerformSelector:@selector(removeFromSuperview)];
    self.imageView_array = NSMutableArray.new;
    for (NSInteger i = 0; i < model.details.count; i ++) {
        BFShOrderModelGoodsModel * goodmodel = model.details[i];
        UIImageView * stoneobs_ui_imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 10, self.class.stoneobs_ui_cell_height-20, self.class.stoneobs_ui_cell_height-20)];
        [stoneobs_ui_imageView sd_setImageWithURL:goodmodel.goods_img.mj_url];
        stoneobs_ui_imageView.contentMode = UIViewContentModeScaleAspectFit;
        [self.scroll_view addSubview:stoneobs_ui_imageView];
        [self.imageView_array addObject:stoneobs_ui_imageView];
        stoneobs_ui_imageView.left = stoneobs_ui_imageView.width * i + i *10 + 12;
        self.scroll_view.contentSize = CGSizeMake(stoneobs_ui_imageView.right, 0);
    }
    if (self.scroll_view.contentSize.width < self.scroll_view.width) {
        self.scroll_view.userInteractionEnabled = NO;
    }else{
        self.scroll_view.userInteractionEnabled = YES;
    }
    
    if (model.details.count == 1) {
        self.scroll_view.hidden = YES;
        self.normalContenView.hidden = NO;
    }else{
        self.scroll_view.hidden = NO;
        self.normalContenView.hidden = YES;
    }
    BFShOrderModelGoodsModel * goodmodel = model.details.firstObject;
    [self.iconImageView sd_setImageWithURL:goodmodel.goods_img.mj_url];
    self.nameLable.text = goodmodel.goods_name;
    self.desLable.text = goodmodel.spec;
    
}
@end
